home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / libv7 / fopenexcl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-10  |  406 b   |  22 lines

  1. /*
  2.  * fopenexcl(name) - fopen(name, "w") with error and errno==EEXIST,
  3.  *    if name exists (V7/V8/V9)
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <errno.h>
  8. #include "fixerrno.h"
  9.  
  10. #define F_OK 0
  11.  
  12. FILE *
  13. fopenexcl(name)
  14. register char *name;
  15. {
  16.     if (access(name, F_OK) >= 0) {    /* name exists */
  17.         errno = EEXIST;
  18.         return NULL;        /* refuse to write on name */
  19.     } else        
  20.         return fopen(name, "w");    /* try to create name */
  21. }
  22.